﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.IO;

namespace Steam_Backup
{
    class Utilities
    {
        public const string s_szSteamApps = "steamapps";
        public const string s_szCommon = "common";

        public static string GetSteamPath()
        {
            //HKEY_CURRENT_USER\Software\Valve\Steam
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam");
            if (key != null)
            {
                object steamPath = key.GetValue(@"SteamPath");
                if (steamPath != null)
                {
                    return steamPath.ToString();
                }
            }

            return string.Empty;
        }

        public static List<FileInfo> GetFiles(string a_szDirectoryPath)
        {
            string szSteamFolder = GetSteamPath();
            if (szSteamFolder.Equals(string.Empty))
            {
                return new List<FileInfo>();
            }

            List<FileInfo> files = (from szFileName in Directory.GetFiles(a_szDirectoryPath)
                                    where szFileName.EndsWith(".ncf")// || szFileName.EndsWith(".ico")
                                    select new FileInfo(szFileName)).ToList<FileInfo>();

            return files;
        }

        public static List<DirectoryInfo> GetFolders(string a_szDirectoryPath)
        {
            string szSteamFolder = GetSteamPath();
            if (szSteamFolder.Equals(string.Empty))
            {
                return new List<DirectoryInfo>();
            }

            List<DirectoryInfo> folders = (from szFolderName in Directory.GetDirectories(a_szDirectoryPath)
                                           //where szFileName.EndsWith(".ncf") || szFileName.EndsWith(".ico")
                                           select new DirectoryInfo(szFolderName)).ToList<DirectoryInfo>();

            return folders;
        }
    }
}
